home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / recvfax / remove.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  107 lines

  1. /*    $Header: /usr/people/sam/fax/recvfax/RCS/remove.c,v 1.14 1994/04/04 18:25:18 sam Rel $
  2. /*
  3.  * Copyright (c) 1990, 1991, 1992, 1993, 1994 Sam Leffler
  4.  * Copyright (c) 1991, 1992, 1993, 1994 Silicon Graphics, Inc.
  5.  *
  6.  * Permission to use, copy, modify, distribute, and sell this software and 
  7.  * its documentation for any purpose is hereby granted without fee, provided
  8.  * that (i) the above copyright notices and this permission notice appear in
  9.  * all copies of the software and related documentation, and (ii) the names of
  10.  * Sam Leffler and Silicon Graphics may not be used in any advertising or
  11.  * publicity relating to the software without the specific, prior written
  12.  * permission of Sam Leffler and Silicon Graphics.
  13.  * 
  14.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  15.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  16.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  17.  * 
  18.  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
  19.  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
  20.  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  21.  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF 
  22.  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE 
  23.  * OF THIS SOFTWARE.
  24.  */
  25. #include "defs.h"
  26. #include <sys/file.h>
  27.  
  28. static void
  29. reallyRemoveJob(const char* op, Job* job, const char* jobname)
  30. {
  31.     char line[1024];        /* call it line to use isCmd() on it */
  32.     char* cp;
  33.     char* tag;
  34.     char* cmd;
  35.     int fd;
  36.     FILE* fp;
  37.  
  38.     fp = fopen((char*) job->qfile, "r+w");
  39.     if (fp == NULL) {
  40.     syslog(LOG_ERR, "%s: cannot open %s (%m)", op, job->qfile);
  41.     sendClient("openFailed", "%s", jobname);
  42.     return;
  43.     }
  44.     fd = fileno(fp);
  45.     /*
  46.      * First ask server to do removal.  If the job is being
  47.      * processed, it will first be aborted.  Otherwise, do
  48.      * the cleanup here.
  49.      */
  50.     cmd = (strcmp(op, "remove") == 0 ? "R" : "K");
  51.     if (notifyServer(job->modem, "%s%s", cmd, job->qfile)) {
  52.     sendClient("removed", "%s", jobname);
  53.     } else if (flock(fd, LOCK_EX|LOCK_NB) == 0) {
  54.     while (fgets(line, sizeof (line) - 1, fp)) {
  55.         if (line[0] == '#')
  56.         continue;
  57.         if (cp = strchr(line, '\n'))
  58.         *cp = '\0';
  59.         tag = strchr(line, ':');
  60.         if (tag)
  61.         *tag++ = '\0';
  62.         while (isspace(*tag))
  63.         tag++;
  64.         if (isCmd("tiff") || isCmd("!tiff") ||
  65.         isCmd("postscript") || isCmd("!postscript")) {
  66.         if (unlink(tag) < 0) {
  67.             syslog(LOG_ERR, "%s: unlink %s failed (%m)", op, tag);
  68.             sendClient("docUnlinkFailed", "%s", jobname);
  69.         }
  70.         }
  71.     }
  72.     if (unlink(job->qfile) < 0) {
  73.         syslog(LOG_ERR, "%s: unlink %s failed (%m)", op, job->qfile);
  74.         sendClient("unlinkFailed", "%s", jobname);
  75.     } else {
  76.         syslog(LOG_INFO, "%s %s completed", 
  77.         strcmp(op, "remove") == 0 ? "REMOVE" : "KILL",
  78.         job->qfile);
  79.         sendClient("removed", "%s", jobname);
  80.     }
  81.     }
  82.     job->flags |= JOB_INVALID;
  83.     (void) fclose(fp);            /* implicit unlock */
  84. }
  85.  
  86. static void
  87. doRemove(Job* job, const char* jobname, const char* arg)
  88. {
  89.     reallyRemoveJob("remove", job, jobname);
  90. }
  91. void
  92. removeJob(const char* modem, char* tag)
  93. {
  94.     applyToJob(modem, tag, "remove", doRemove);
  95. }
  96.  
  97. static void
  98. doKill(Job* job, const char* jobname, const char* arg)
  99. {
  100.     reallyRemoveJob("kill", job, jobname);
  101. }
  102. void
  103. killJob(const char* modem, char* tag)
  104. {
  105.     applyToJob(modem, tag, "kill", doKill);
  106. }
  107.